package io.renren.utils;

import java.util.HashMap;
import java.util.Map;

public class QrLogicUtil {

	private static Map<String, String> gradeMap = new HashMap<String, String>();// 年级
	private static Map<String, String> subjectMap = new HashMap<String, String>();// 科目
	private static Map<String, String> fascicleMap = new HashMap<String, String>(); // 册别
	private static Map<String, String> versionMap = new HashMap<String, String>(); // 教版
	static {
		// 年级
		gradeMap.put("7", "七年级");
		gradeMap.put("8", "八年级");
		gradeMap.put("9", "九年级");

		// 科目
		subjectMap.put("1", "语文");
		subjectMap.put("2", "数学");
		subjectMap.put("3", "英语");
		subjectMap.put("4", "物理");
		subjectMap.put("5", "化学");
		subjectMap.put("6", "历史");
		subjectMap.put("7", "地理");
		subjectMap.put("9", "生物");
		subjectMap.put("A", "思想品德");
		subjectMap.put("B", "道德与法治");

		// 册别
		fascicleMap.put("1", "上册");
		fascicleMap.put("2", "下册");
		fascicleMap.put("3", "全册");

		// 教版
		versionMap.put("1", "人教版");
		versionMap.put("2", "苏教版");
		versionMap.put("3", "沪科版");
		versionMap.put("4", "教科版");
		versionMap.put("5", "科学版");
		versionMap.put("6", "陕人教版");
		versionMap.put("7", "北师大版");
	}

	public static void main(String[] args) {
		String qrCode = "YS20-7211-T26";
		String qrDesc4YS = getQrDesc4YS(qrCode);
		System.out.println(qrDesc4YS);

	}

	public static String getQrDesc4YS(String qrCode){
		if(qrCode.startsWith("YYxtxZL")){
			return "二维码标识为：" + qrCode;
		}

		if(qrCode.startsWith("YS20-7211")){
			return null;
		}
		// YS20-7211-T26
//		if(qrCode.startsWith("YS20")){
//			String desc = "";
//			String nice = "视频微课即将上线，敬请期待！ 预设值:";
//			String baseStr = qrCode.split("-")[1];
//			String[] base = baseStr.split("");
//			String baseInfo = "用于<" + gradeMap.get(base[0]) + "_" + subjectMap.get(base[1]) + "_" + fascicleMap.get(base[2]) + "_" + versionMap.get(base[3])
//					+ ">大象e学的";
//			String extra = qrCode.split("-")[2];
//			String start = extra.substring(0, 1);
//			if (start.equals("D")) {
//				desc = "答案页";
//			}
//			if (start.equals("C")) {
//				String content = extra.substring(1);
//				if (content.equals("2")) {
//					desc = "封二";
//				}
//				if (content.equals("3")) {
//					desc = "封三";
//				}
//				if (content.equals("4")) {
//					desc = "封底";
//				}
//			}
//			if (start.equals("T")) {
//				desc = "习题旁、课时旁或评价卷中";
//			}
//			if (start.equals("F")) {
//				desc = "收费的二维码";
//			}
//			return nice + qrCode + "," + baseInfo + desc;
//		}

		return null;
	}


	/**
	 * 根据二维码的值获取二维码的回复描述
	 *
	 * @param qrCode
	 * @return
	 */
	public static String getQrDesc(String qrCode) {
		String nice = "视频微课即将上线，敬请期待！ 预设值:";
		if (!qrCode.startsWith("JX19-")) {
			return nice + qrCode;
		} else {
			String desc = "";
			String baseStr = qrCode.split("-")[1];
			if (baseStr.length() == 2) {
				if (baseStr.equals("C2")) {
					desc = "用于封二";
				}
				if (baseStr.equals("C3")) {
					desc = "用于封三";
				}
				if (baseStr.equals("C4")) {
					desc = "用于封底";
				}
				return nice + qrCode + "," + desc;
			}
			String[] base = baseStr.split("");
			String baseInfo = "用于<" + gradeMap.get(base[0]) + "_" + subjectMap.get(base[1]) + "_" + fascicleMap.get(base[2]) + "_" + versionMap.get(base[3])
					+ ">基础训练的";
			String extra = qrCode.split("-")[2];
			String start = extra.substring(0, 1);
			if (start.equals("D")) {
				desc = "答案页";
			}
			if (start.equals("C")) {
				String content = extra.substring(1);
				if (content.equals("2")) {
					desc = "封二";
				}
				if (content.equals("3")) {
					desc = "封三";
				}
				if (content.equals("4")) {
					desc = "封底";
				}
			}
			if (start.equals("T")) {
				desc = "习题旁、课时旁或评价卷中";
			}
			if (start.equals("F")) {
				desc = "收费的二维码";
			}
			return nice + qrCode + "," + baseInfo + desc;
		}
	}
}
